package server.handler.friendHandler;

import com.alibaba.fastjson.JSONObject;
import common.EnvelopeMessage;
import common.bodies.FriendShipBody;
import server.dao.FriendDao;
import server.handler.SimpleHandler;
import server.session.Session;

public class FriendBlockCancelHandler implements SimpleHandler {
    @Override
    public void handle(EnvelopeMessage msg, Session session) {
        JSONObject body = msg.getBody();
        Integer friendId = body.getInteger("friendId");
        Integer userId = body.getInteger("userId");
        String userName = body.getString("userName");
        String friendName = body.getString("friendName");
        FriendShipBody ship = new FriendShipBody(userId, userName, friendId, friendName, -1);
        new FriendDao().updateFriendShip(ship);
        JSONObject object = new JSONObject();
        object.put("success",true);
        EnvelopeMessage back = new EnvelopeMessage("friend","blockCancel",object);
        String json = JSONObject.toJSONString(back);
        System.out.println("服务端返回"+json);
        session.send(json);
    }
}
